<?php


class PointSaleFormAjax extends WebAjax{
    
    public function processRequest($action_type,  HttpRequest $request,HttpResponse $response) {
        switch ($action_type){
            case "getCity":
                return $this->getCity($request,$response);
           case "getCaptcha":
                return $this->getCaptcha($request,$response);
        }
        return '';
    }
    
    public function getCaptcha(HttpRequest $request,HttpResponse $response){
        $captcha = array();
        include_once APPLICATION_DIR.'/application/data/captcha.php';
        global $_CAPTCHA;
        $captcha_key = array_keys($_CAPTCHA);
        $captcha_size = count($captcha_key);
        $temp_captcha = $captcha_key[rand(0,$captcha_size-1)];
        $captcha[0] = $temp_captcha;
        $captcha[1] = $_CAPTCHA[$temp_captcha];
        return $captcha;
    }

    public function getCity(HttpRequest $request,HttpResponse $response){
        $city = new CityRM();
        $this->orm_builder->buildCity($city); 
        $city->findAllValidCountry($request->get("country_id"));
        $city_arr = array();
        while($city->fetch()){
            $city_arr[] = array("ID"=>$city->ID,"NAME"=>$city->NAME) ;
        }
        return $city_arr;
    }
}